
<template>
    <div class="mulu subchild">
        <header class="head">
                <van-icon name="arrow-left" size="20" @click="ClickLeft"/>
                <div>目录</div>
                <van-icon  name="manager"  size="20"/>
        </header>
        <div v-if="mulist.length!=0">
            <div class="zhangjie">
             <span>目录</span> <span>共{{mulist.length}}章</span> <span class="shunxu" @click="shunxua">{{shunxu}}</span>
            </div>
            <div v-for="(item,index) in mulist" :key="index" @click="neirong(item,index)" class="xiangxi">
                {{item.title}}
            </div>
        </div>
        <div v-else>
            <van-loading size="24px" style="text-align:center">目录加载中...</van-loading>
        </div>
    </div>
    
</template>

<script>
import {mapState,mapMutations} from "vuex";
export default {
    data(){
        return{
            mulist:[],
            shunxu:"倒序",
            index:0,
        }
    },
    computed:{
        ...mapState(["booksList"])
    },
    methods:{
        ...mapMutations(["setBooksList"]),
        ClickLeft(){
            this.$router.back(-1);
        },
        shunxua(){
            this.index++
            if(this.index%2==0){
                this.shunxu='倒序'
                this.mulist= this.mulist.reverse()
            }else{
                this.shunxu='正序'
                this.mulist= this.mulist.reverse()
            }
        },
        neirong(item,index){
            // console.log(item.chapterId)
            this.$router.push({name:"booknei",query:{chapterId:item.chapterId}})
        }
    },
    mounted(){
        this.$ajax.fictionChapte({
            fictionId:this.$route.query.fictionId
        }).then(res=>{
            if(res.code==200){
                this.mulist=res.data.data
                this.setBooksList(res.data.data)
                // console.log(this.booksList)
            }
        })
    }
}
</script>

<style lang="scss" scoped>
.head{
    position: fixed;
    top: 0;
    height: 46px;
    padding: 0 20px;
    color: #fff;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #b83320;
    div{
        font-size: 16px;

    }
}
.zhangjie{
    width: 100%;
    padding: 10px 20px;
    font-size: 14px;
    border-bottom: 1px solid #f8f8f8;
    background-color: #fff;
    .shunxu{
        float:right;
    }
}
.xiangxi{
    padding: 10px 20px;
    width: 100%;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    color: #999;
    font-size: 14px;
    border-bottom: 1px solid #f8f8f8;
    background-color: #fff;
}
</style>

